<?php

namespace App\Models\Traits\Fields;

trait CateFields
{
    //字段注释,验证时可作custom部分
    protected $comments = [
        'name'  => '标识名',
        'title' => '分类名',
        'parent_id' => '上级分类',
        'order' => '排序',
        'groups' => '分组设置',
        'sets'  => '分类设置',
    ];


    //创建规则 将规换rules    
    protected $createRules = [
        'title' => 'required',
        'name'  => 'required|unique:cates|regex:/^[A-Za-z][A-Za-z0-9_]+$/',
    ];

    //编辑规则 将规换rules 
    protected $updateRules = [
        'id'    => 'required',
        'title' => 'required',
        'name'  => 'required|unique:cates|regex:/^[A-Za-z][A-Za-z0-9_]+$/',
    ];

    //规则消息
    protected $messages = [
        'id.required'  => '未指定id',
        'name.unique' => '分类标识已存在',
        'name.regex' => '分类标识只能使用字母和下划线',
    ];

    //规则消息
    protected $formSet = [
        'id'    => [
            'display' => 'ID'
        ],
        'title' => [
            'text' => '分类名称',
            'rules' => 'required',
        ],
        'name'  => [
            'text' => '分类标识',
            'rules' => 'required|unique:cates|regex:/^[A-Za-z][A-Za-z0-9_]+$/'
        ],
        'parent_id' => [
            'hidden' => '上级分类',
        ],
        'order' => [
            'hidden' => '排序',
        ],
        'groups' => [
            'tags' => '分组设置'
        ],
        'publish'  => [
            'switch' => '是否允许发布',
            'default' => 1
        ],
    ];

    protected $formOnlyCreate = [];
    protected $formOnlyUpdate = [];
    // 枚举设置
    protected $enums = [];
}
